﻿Imports VendasBLL
Imports VendasDAL
Public Class AgendamentoRelFRM
    Dim Codigo As Integer
    Private Sub BTNLocalizar_Click(sender As System.Object, e As System.EventArgs) Handles BTNLocalizar.Click

        Dim obj As New ConsultaClientesFRM
        obj.tipo = "ret"
        obj.ShowDialog()
        If (Not IsNothing(obj.ObjC)) Then
            Dim ObjCli As New ClientesBLL
            ObjCli = obj.ObjC
            TXTDescricao.Text = ObjCli.Nome
            Codigo = ObjCli.Codigo
            ObjCli = Nothing
        End If
        obj = Nothing

    End Sub
#Region "Relatorio"
    Public Sub gerarelatrio(titulo As String, formula As String)
        Try
            Dim frmrecursos As New RelatoriosVendaFRM
            Dim rpt As New AgendamentoREL

            Try
                rpt.SetDatabaseLogon(usuario, senha)
                rpt.SetParameterValue(0, titulo)
                rpt.RecordSelectionFormula = formula
                frmrecursos.CRVRelatorio.ShowGroupTreeButton = False
                frmrecursos.CRVRelatorio.ReportSource = rpt
                frmrecursos.ShowDialog()
            Catch ex As Exception
                MessageBox.Show(ex.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Try
            frmrecursos.Dispose()
            rpt = Nothing
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Finally

        End Try
    End Sub
#End Region
    Private Sub BTNOk_Click(sender As System.Object, e As System.EventArgs) Handles BTNOk.Click
        Try

            If (Codigo <> 0 Or TXTDescricao.Text <> "") Then
                gerarelatrio("Relatório de Agendamentos: " & TXTDescricao.Text, "{Ofi_Cliente.cli_codigo} =" & Codigo & " and {vw_Agendamento.age_data} >= '" & DTPInicio.Value.ToString("yyyy-MM-dd") & "' and {vw_Agendamento.age_data}<= '" & DTPFim.Value.ToString("yyyy-MM-dd") & "'")
            Else : Throw New Exception("Informe Cliente!")
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End Try

    End Sub
End Class